<template>
	<view class="beijingse mainpadding" v-if="pageShow">
		<view class="jfbox">
			<view class="fonweight xiaobai textcenter" style="font-size: 80rpx;" v-if="type==1">{{userInfo.score}}</view>
			<view class="fonweight xiaobai textcenter" style="font-size: 80rpx;" v-if="type==2">{{userInfo.money}}</view>
			<view class="fonweight xiaobai textcenter" style="font-size: 80rpx;" v-if="type==3">{{userInfo.jb_num}}</view>
			
			<view class=" xiaobai bigtext margin_top1 textcenter">我的{{text}}</view>
			<view class="flexcenter sbianb margin_top">
				<view class="xbbtn flexcenter" v-if="(type==2||type==3)" @click="jumpdetail('/pages_mypage/tixian?type=',type)">提现</view>
				<view class="xbbtn flexcenter" v-if="type==1" @click="zzShow = true">转赠</view>
			</view>
		</view>
		<view class=" margin_top4" v-if="list.total">
			<view class="dingwei">
				<view class="sanshier fonweight zhonghei" >{{text}}明细</view>
				<image class="xiahx" src="../static/image/system/ztxhx.png" mode=""></image>
			</view>
			<view class="mainpadding ffffff radius margin_top">
				<view class="shangbj flexbetween xiahuaxian" v-for="item in list.data" :key="item.id">
					<view class="">
						<view class="ershiba fonweight zhonghei">{{item.memo}}</view>
						<view class="strongtext margin_top1 xiaohui">{{item.createtime_text}}</view>
					</view>
					<view class="flexright">
						<view class="sanshier fonweight xiaocheng" v-if="type==1">{{item.score}}</view>
						<view class="sanshier fonweight xiaocheng" v-if="type==2">{{item.money}}</view>
						<view class="sanshier fonweight xiaocheng" v-if="type==3">{{item.money}}</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="zzShow" :round="10" mode="center" :closeable='true' @close='zzShow = false'>
		    <view style="padding: 30rpx;">
		        <view style="font-size: 35rpx;text-align: center;">转赠</view>
				<view style="margin-top: 30rpx;">
					<u-input placeholder="请输入转赠目标用户电话" type='number' v-model='mobile' maxlength='11'>
						<u--text text="目标用户电话:" slot="prefix" margin="0 3px 0 0" color="#333"></u--text>
					</u-input>
				</view>
				<view style="margin-top: 30rpx;">
					<u-input placeholder="请输入转赠数量" type='number' v-model='score' maxlength='-1'>
						<u--text text="转赠数量:" slot="prefix" margin="0 3px 0 0" color="#333"></u--text>
					</u-input>
				</view>
				<view  style="margin-top: 30rpx;display: flex;justify-content: center;align-items: center;">
					<view style="padding: 15rpx 60rpx;background-color: #FF8534;color: #fff;border-radius: 15rpx;" @click="sendFun">确认</view>
				</view>
		    </view>
		</u-popup>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				userInfo: {},
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				pageShow:false,
				type:1,//1积分，2佣金，3金币
				text:"积分",
				isSH:true,
				zzShow:false,
				mobile:'',
				score:''
			}
		},
		onLoad(options) {
			this.type = options.type
			let text = ""
			if(options.type==1){
				text = "积分"
			}else if(options.type==2){
				text = "佣金"
			}else if(options.type==3){
				text = "金币"
			}
			this.text = text
			uni.setNavigationBarTitle({
				title:"我的"+text
			})
		},
		onShow() {
			this.userinfomsg()
			this.init()
			// #ifdef MP-WEIXIN
			this.getsystem()
			// #endif
		},
		methods: {
			sendFun(){
				if(!this.mobile){
					uni.showToast({
						icon:"none",
						title:'请输入转赠目标用户电话'
					})
					return
				}
				let phoneReg = /^1[3-9]\d{9}$/;
				if (!phoneReg.test(this.mobile)) {
					uni.showToast({
						title: '请输入正确的手机号码',
						icon: 'none',
					});
					return
				}
				if(!this.score){
					uni.showToast({
						icon:"none",
						title:'请输入转增积分'
					})
					return
				}
				httpRequest.request('/api/user/sendToUserScore', 'GET', {
					mobile: this.mobile ,
					score: this.score
				}).then(res => {
					this.zzShow =false
					if(res.code == 1){
						uni.showToast({
							icon:"none",
							title:'赠送成功'
						})
						
					}else{
						uni.showToast({
							icon:"none",
							title:res.msg||'赠送失败'
						})
					}
				})
			},
			getsystem() {
				let _this = this
				// 条件编辑只在微信小程序显示
				const accountInfo = wx.getAccountInfoSync();
				let version_code = accountInfo.miniProgram.version // 小程序 版本号
				console.log(accountInfo, '小程序版本号')
				httpRequest.request('/api/index/checkApply', 'GET', {
					platform:"wechat" ,
					version_code:version_code||100
				}).then(res => {
					this.isSH = res.data
				})
			},
			userinfomsg() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
					this.pageShow = true
				})
			},
			init(isPage, page) {
				let _this = this
				let url = "/api/user/scoreLog"
				let data = {
					page: page || 1,
					limit: _this.limit,
				}
				if(this.type==2){
					url="/api/user/moneyLog"
				}
				if(this.type==3){
					url="/api/user/jbLog"
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.xiahuaxian:last-child {
		padding-bottom: 0;
		border: none;
	}

	.shangbj {
		margin-top: 30rpx;
	}

	.shangbj:first-child {
		margin-top: 0rpx;
	}

	.xiahx {
		width: 124rpx;
		height: 10rpx;
		position: absolute;
		bottom: 0;
		left: 0;
	}

	.sbianb {
		padding-top: 25rpx;
		border-top: 1rpx solid rgba(255, 255, 255, .3);
	}

	.xbbtn {
		width: 194rpx;
		height: 65rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		border: 2rpx solid #FFFFFF;
		color: #FFFFFF;
		border-radius: 10rpx;
	}

	.jfbox {
		background-size: 100% 100%;
		padding: 83rpx 0rpx 23rpx;
		background-image: url('');
	}
</style>